package com.tanhua.app.controller;

import com.tanhua.app.service.VideoService;
import com.tanhua.vo.PageBeanVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
public class VideoController {

    @Autowired
    private VideoService videoService;

    @GetMapping(value = "/smallVideos",name="小视频的分页查询")
    public ResponseEntity findVideo(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10")Integer pagesize) throws IOException {
        // page:1 pageSize:10
        if(page==0){
            page=1;
        }
        PageBeanVo pageBeanVo = videoService.findVideo(page, pagesize);
        return ResponseEntity.ok(pageBeanVo);
    }


    @PostMapping(value = "/smallVideos",name="小视频的发布")
    public ResponseEntity saveVideo(MultipartFile videoThumbnail,MultipartFile videoFile) throws IOException {

        return videoService.saveVideo(videoThumbnail,videoFile);
    }


    @PostMapping(value = "/smallVideos/{uid}/userFocus",name="关注小视频作者")
    public ResponseEntity guanzhu(@PathVariable("uid") Long followUserId) throws IOException {

        return videoService.guanzhu(followUserId);
    }


    @PostMapping(value = "/smallVideos/{uid}/userUnFocus",name="撤销关注的小视频作者")
    public ResponseEntity unguanzhu(@PathVariable("uid") Long followUserId) throws IOException {
        System.out.println(followUserId);
        return videoService.unguanzhu(followUserId);
    }




}
